package com.yf1706.service;

import java.util.Date;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder.In;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yf1706.bean.ExamArrangement;
import com.yf1706.bean.ExamPaper;
import com.yf1706.dao.jpa.ExamArrangementJDAO;
import com.yf1706.dao.jpa.ExamPaperJDAO;
import com.yf1706.dao.mybatis.ExamArrangementMDAO;

@Service
@Transactional
public class ExamArrangementService {
	
	@Autowired
	private ExamArrangementMDAO emdao;
	
	@Autowired
	private ExamArrangementJDAO ejdao;
	
	@Autowired
	private ExamPaperJDAO epjdao;
	
	
	public List<ExamArrangement> queryAllExamArrangement() {
		
		return emdao.queryAllExamArrangement();
	}

	public void add(String examAN, String examP, Date eaStartTime, Date eaEndTime, String eaNum,int allScore,int snum,int ss,int mnum,int ms,int jnum,int js,int fnum,int fs) {
		ExamArrangement e=new ExamArrangement();
		ExamPaper ep=new ExamPaper();
		ep.setExamPaperScore(allScore);
		ep.setExamPaperSnum(snum);
		ep.setExamPaperS(ss);
		ep.setExamPaperMnum(mnum);
		ep.setExamPaperM(ms);
		ep.setExamPaperJnum(jnum);
		ep.setExamPaperJ(js);
		ep.setExamPaperFnum(fnum);
		ep.setExamPaperF(fs);
		ep.setExamPaperName(examP);
		epjdao.save(ep);
		e.setExamArrangementName(examAN);
		e.setExamPaper(ep);
		e.setStartTime(eaStartTime);
		e.setEndTime(eaEndTime);
		e.setExamineeNum(Integer.parseInt(eaNum));
		ejdao.save(e);
		
		
		
	}

	public void updataExamArrange(int examArrangementId,String examAN,int examPaperId, Date eaStartTime, Date eaEndTime,
			int parseInt) {
		ExamArrangement e=ejdao.findByExamArrangementId(examArrangementId).get(0);
		e.setExamArrangementName(examAN);
		e.setExamPaper(epjdao.findByExamPaperId(examPaperId).get(0));
		e.setStartTime(eaStartTime);
		e.setEndTime(eaEndTime);
		e.setExamineeNum(parseInt);
		ejdao.save(e);
	}

	public void deleteByExamArrangementId(int examArrangementId) {
		ejdao.deleteById(examArrangementId);
		
	}

	
	//通过安排名模糊查询
	public List<ExamArrangement> queryByExamArrangementName(String examArrangementName) {
		// TODO Auto-generated method stub
		return emdao.queryByExamArrangementName(examArrangementName);
	}
	
}
